<%@ page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="perm" uri="/WEB-INF/tld/perm.tld"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
	<script>var ctx="${ctx}";</script>
	<head>
	    <meta charset="utf-8">
	    <meta name="viewport" content="width=device-width, initial-scale=1.0">
	    <title>Mr Cargo管理平台</title>
	    <meta name="keywords" content="体验,友好,高级管理台,易用,高性能,高扩展性,bootstrap框架,响应式后台">
	    <meta name="description" content="这是一个完全响应式，基于Bootstrap3最新版本开发的扁平化主题，她采用了主流的左右两栏式布局，使用了Html5+CSS3等现代技术">
	    <meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="Cache-Control" content="no-cache, must-revalidate">
		<meta http-equiv="expires" content="Wed, 26 Feb 209908:21:57 GMT"> 
	    <!--[if lt IE 8]>
	    <meta http-equiv="refresh" content="0;ie.html" />
	    <![endif]-->
	    <link rel="shortcut icon" href="favicon.ico"> 
		<link rel="shortcut icon" href="favicon.ico"> 
		<link href="${ctx}/static/css/bootstrap.min.css?v=${static_version}" rel="stylesheet">
		<link href="${ctx}/static/css/font-awesome.min.css?v=4.4.0?v=${static_version}" rel="stylesheet">
		<link href="${ctx}/static/css/plugins/summernote/summernote.css?v=${static_version}" rel="stylesheet">
		<link href="${ctx}/static/css/plugins/summernote/summernote-bs3.css?v=${static_version}" rel="stylesheet">
		<link href="${ctx}/static/plugins/laypage/laypage.css?v=${static_version}"  rel="stylesheet">
		<link href="${ctx}/static/css/plugins/iCheck/custom.css?v=${static_version}" rel="stylesheet">
		<link href="${ctx}/static/css/plugins/chosen/chosen.css?v=${static_version}" rel="stylesheet">
		<link href="${ctx}/static/css/animate.min.css?v=${static_version}" rel="stylesheet">
		<link href="${ctx}/static/js/plugins/layer/laydate/laydate.css?v=${static_version}" rel="stylesheet">
		<link href="${ctx}/static/plugins/jquery-treetable/jquery.treetable.css?v=${static_version}" rel="stylesheet">
		<link href="${ctx}/static/plugins/jquery-treetable/jquery.treetable.theme.default.css?v=${static_version}" rel="stylesheet">
		<link href="${ctx}/static/css/style.min.css?v=4.0.0" rel="stylesheet">
		
	</head>
	
	<style>
        .jstree-open>.jstree-anchor>.fa-folder:before{content:"\f07c"}.jstree-default .jstree-icon.none{width:0}
    </style>
	
	<body class="gray-bg">
       	<div class="ibox float-e-margins">
               <div class="ibox-content">
			    	<div class="ibox float-e-margins">
		                <form class="form-group" id="sysResource_table_form">	
		                	<input type="hidden" name="orderBy" value="create_date desc">
		                	<input type="hidden" name="status" value="0">
		                	<input type="hidden" name="parentId" id="sysDepartment_parentId">
		                	<div class="row">
		                		<perm:hasPermission code="resource/find">
		                        <div class="col-md-2 col-sm-2"><input id="keyword" name="keyword" type="text" placeholder="请输入关键字" class="form-control" /></div>
				     	  		<div class="col-md-4 col-sm-4">
		                            <div class="input-group">
		                                <input id="startTime" type="text" class="input-md form-control" placeholder="开始时间"  name="startTime">
							        	<span class="input-group-addon">至</span>
							        	<input id="endTime" type="text" class="input-md form-control" placeholder="结束时间"  name="endTime">
		                            </div>
							    </div>
								<div class="col-md-1 col-sm-1">
									<button onclick="loadTreeTable()" id="sysResource_table_search" type="button" class="btn btn-outline btn-block btn-primary">查询</button>
								</div>
								</perm:hasPermission>
								<perm:hasPermission code="resource/insertGet">
							    <div class="col-md-1 col-sm-1 pull-right ">
									<a  onclick="clickInsertGet()" class="btn btn-block btn-outline btn-primary">添加</a>
							    </div>
							    </perm:hasPermission>
		                    </div>
		                </form>
						<table id="sysResource_table" data-params='{}' data-action="${ctx}/resource/find?status=0" data-datatable="true"  class="treetable footable table">
						  	<thead>
					          <tr>
					            <th>资源名称</th>
					            <th>URI</th>
					            <th>所属资源</th>
					            <th>是否台菜单</th>
					            <th>生成人</th>
					            <th>生成时间</th>
					            <th>最后更新人</th>
					            <th>更新时间</th>
					            <th>描述</th>
					            <th  data-sort-ignore="true" data-crud="true" data-title='{"uid":"id"}' data-hide="phone">操作
				      			  <div style="display: none;" class="center hidden-phone">
				      			  		<perm:hasPermission code="resource/updateGet">
					      			  		<button onclick="clickUpdateGet(this)" style="margin-left:3px;margin-top:3px" data-id=":uid" type="button" class="btn btn-info btn-outline btn-xs"><i class="fa fa-pencil"></i>&nbsp;更新</button>
									  	</perm:hasPermission>
				      			  		<perm:hasPermission code="resource/delete">
					      			  		<button onclick="deleteAjax(this)" style="margin-left:3px;margin-top:3px" data-id=":uid" type="button" class="btn btn-danger btn-outline btn-xs"><i class="fa fa-times"></i>&nbsp;删除</button>
									  	</perm:hasPermission>
								  </div> 
			      		      	</th>
					          </tr>
					        </thead>
					        <tbody>
					        </tbody>
					    </table>
					</div>
				</div>
             </div>
		
	<script src="${ctx}/static/js/jquery.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/bootstrap.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/validate/jquery.validate.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/validate/messages_zh.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/summernote/summernote.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/summernote/summernote-zh-CN.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/chosen/chosen.jquery.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/layer/laydate/laydate.js?v=${static_version}"></script>
	<script src="${ctx}/static/plugins/laypage/laypage.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/eModal.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/cookie.js?v=?v=${static_version}""></script>
	<script src="${ctx}/static/js/plugins/iCheck/icheck.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/jquery-ui/jquery-ui.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/plugins/jquery-treetable/jquery.treetable.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/content.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/contabs.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/common/common.js?v=${static_version}"></script>
	
	<script>
	
		var clickId="";
	
		var loadTreeTable=function(){
			$.ajax({  
				url:$("#sysResource_table").data("action"),  
				type: 'POST',
				data:{
					keyword:$("#keyword").val(),	
					startTime:$("#startTime").val(),							
					endTime:$("#startTime").val()							
				}, 
				dataType:'json',  
				success:function(response){
					if(response.code==0){
						var html=[];
					 	for(var i=0;i<response.data.length;i++){
						 	var row=response.data[i];
						 	var id=row.id;
						 	var parentId=row.parentId;
						 	var name=row.name;
						 	var createUser=row.createUser;
						 	var createDate=row.createDate;
						 	var updateUser=row.updateUser;
						 	var updateDate=row.updateDate;
						 	var parentName=row.parentName;
						 	var isMenu=row.isMenu;
						 	var url=row.url;
						 	var lastNode=row.lastNode;
						 	var remark=row.remark;
						 	if(parentId!=null&&parentId!=""){
						 		html.push('<tr data-id="'+id+'" data-tt-id="'+id+'" data-tt-parent-id="'+parentId+'">');
						 	}else{
						 		html.push('<tr data-id="'+id+'" data-tt-id="'+id+'">');
						 	}
						 	html.push('	<td class="file2">'+name+'</td>');
						 	html.push('	<td>'+((url==undefined ||url==null || url=='')? "&nbsp;":url)+'</td>');
						 	html.push('	<td>'+((parentName==undefined ||parentName==null || parentName=='')? "&nbsp;":parentName)+'</td>');
						 	html.push('	<td data-type="enum" data-opt=\'{"1":"是","2":"否"}\'>'+isMenu+'</td>');
						 	html.push('	<td>'+createUser+'</td>');
						 	html.push('	<td data-type="datetime">'+createDate+'</td>');
						 	html.push('	<td>'+updateUser+'</td>');
						 	html.push('	<td data-type="datetime">'+updateDate+'</td>');
						 	html.push('	<td>'+((remark==undefined ||remark==null || remark=='') ? "&nbsp;":remark)+'</td>');
						 	html.push('<td>');
						 	
						 	if(lastNode){
						 		html.push('<button onclick="deleteAjax(this)"   data-url="${ctx}/resource/delete"  data-id="'+id+'" type="button" class="btn btn-primary btn-xs">删除</button>');
						 	}
						 	html.push('<button onclick="clickUpdateGet(this)" style="margin-left:3px"  data-type="update" data-title="更新" data-url="${ctx}/resource/update"  data-id="'+id+'" type="button" class="btn btn-primary btn-xs">更新</button>');
						 	html.push('</td>');
						 	html.push('</tr>');
					 	}
					 	
					 	$("#sysResource_table").treetable('destroy');
					 	$("#sysResource_table tbody").html(html.join(""));
					 	$("#sysResource_table").treetable({expandable:true});
						
					 	jQuery.dataFormater();
					 	
						$("#sysResource_table tbody").on("mousedown", "tr", function() {
						  	$(".selected").not(this).removeClass("selected");
						  	$(this).toggleClass("selected");
						  	clickId=$(this).data("id");
						});

						$("#sysResource_table .file2").draggable({
						  helper: "clone",
						  opacity: .75,
						  refreshPositions: true,
						  revert: "invalid",
						  revertDuration: 300,
						  scroll: true
						});
						/*
						$("#sysResource_table .file2").each(function() {
						  $(this).parents("#sysResource_table tr").droppable({
						    accept: ".file2",
						    drop: function(e, ui) {
						      var droppedEl = ui.draggable.parents("tr");
						      $("#sysResource_table").treetable("move", droppedEl.data("ttId"), $(this).data("ttId"));
						    },
						    hoverClass: "accept",
						    over: function(e, ui) {
						      var droppedEl = ui.draggable.parents("tr");
						      if(this != droppedEl[0] && !$(this).is(".expanded")) {
						        $("#sysResource_table").treetable("expandNode", $(this).data("ttId"));
						      }
						    }
						  });
						});
						*/
					}else{
					    $.confirm({cancelButton: "关   闭",title: '提示',text: (me).data("title")+"错误!"||"保存数据错误!"});
					}
				}  
		    }); 
		}
		
		$(document).ready(function() {
			loadTreeTable();
		});
		
		var clickInsertGet=function(){
			eModal.ajax({
	   	        url: "${ctx}/resource/updateGet",
	   	        title:'添加资源',
	   	        loading:true,
	   	     	useBin:true,
	   	        size: eModal.size.sm,
	   	        subtitle: '请区分菜单资源和权限资源',
	   	        buttons: [
	   	            {text: '保存', style: 'info', close: false, click:function(){
	   	            	console.log("---------["+$("#chosen-select3").val()+"]");
	   	 			console.log($("#chosen-select3").val().join(","));
	   	 		    	$.ajax({  
	   	 					url:'${ctx}/resource/add',  
	   	 					data:{
								parentId:$("#resources_parent").val(),							
								name:$("#name").val(),							
								remark:$("#remark").val(),							
								isMenu:$("input[name='isMenu']:checked").val(),							
								url:$("#url").val(),
								roleIds:$("#chosen-select3").val().join(","),
								id:$("#id").val()
							}, 
							type: 'POST',
	   	 					dataType:'json',  
	   	 					success:function(response){
	   	 						if(response.code==0){
	   	 							eModal.close();
	   	 							$("#sysResource_table_search").click();
	   	 						}else{
	   	 						    $.confirm({cancelButton: "关   闭",title: '提示',text: (me).data("title")+"错误!"||"保存数据错误!"});
	   	 						}
	   	 					}  
	   	 			    }); 
	   	            }},{text: '取消', style: 'danger', close: false, click:function(){
	   	            	eModal.close();
	   	            }}
	   	        ],
	   	    });
		}
		
		var clickUpdateGet=function(me){
			eModal.ajax({
	   	        url: "${ctx}/resource/updateGet?id="+$(me).data("id"),
	   	        title:'更新资源',
	   	        loading:true,
	   	     	useBin:true,
	   	        size: eModal.size.sm,
	   	        subtitle: '请区分菜单资源和权限资源',
	   	        buttons: [
	   	            {text: '保存', style: 'info', close: false, click:function(){
	   	 		    	$.ajax({  
	   	 					url:'${ctx}/resource/update',  
	   	 					data:{
	   	 						parentId:$("#resources_parent").val(),	
								name:$("#name").val(),							
								remark:$("#remark").val(),							
								isMenu:$("input[name='isMenu']:checked").val(),									
								url:$("#url").val(),
								id:$("#id").val()
							}, 
							type: 'POST',
	   	 					dataType:'json',  
	   	 					success:function(response){
	   	 						if(response.code==0){
	   	 							eModal.close();
	   	 							$("#sysResource_table_search").click();
	   	 						}else{
	   	 						    $.confirm({cancelButton: "关   闭",title: '提示',text: (me).data("title")+"错误!"||"保存数据错误!"});
	   	 						}
	   	 					}  
	   	 			    }); 
	   	            }},{text: '取消', style: 'danger', close: false, click:function(){
	   	            	eModal.close();
	   	            }}
	   	        ],
	   	    });
			return false;
		}
		
		$(function(){
		
			$("#chosen-select").chosen().change(function(){
				$.ajax({  
 					url:'${ctx}/resource/list',  		 					
 					data:{
						sortNo:$("#sortNo").val(),							
						status:0							
					},   
 					dataType:'json',  
 					success:function(response){
 						if(response.code==0){
 							var html=[];
 							var data=response.data||[];
 							for(var i=0;i<data.length;i++){
 								html.push('<option value="'+data[i].id+'" hassubinfo="true">'+data[i].name+'</option>');
 							}
 							$("#chosen-select").html(html.join(""));
 							$("#chosen-select").trigger("chosen:updated");
 						}
 					}  
 			    });
			});
		
			jQuery.searchFormInit();
		    
		});
	</script>
	
	</body>
</html>